
<?php 
	
	session_start();
	
	#session_destroy();
	include_once "../config/config.php";

	function auth($email, $password) {
		$users = array (
				'sami.ventorero@gmail.com'	=>	'1234', 
				'a'							=>	'a'
		);

		#var_dump($email);
		#var_dump($password);
		#var_dump($users[$email]);		
		
		if(isset($users[$email]) && $users[$email]===$password)
			return(1);
		else 
			return(0);
	}
	$error = 0;
	if(isset($_POST['TS_email']) || isset($_POST['TS_password'])){
		$authed = auth($_POST['TS_email'], $_POST['TS_password']);
		
		if ($authed)
			$_SESSION['TS_email'] = $_POST['TS_email'];
		else
			$error = 1;
	}
	
	if(isset($_SESSION['TS_email']))
		header('Location: index.php');
	
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Tikvat Shlomo</title>

    <link rel="stylesheet" href="<?php echo $path;?>css/bootstrap.min.css" media="all">
    <link rel="stylesheet" href="<?php echo $path;?>css/bootstrap-responsive.min.css" media="all">    
    <script type="text/javascript" src="<?php echo $path;?>js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="<?php echo $path;?>js/bootstrap.min.js"></script>
    
    
    
    
    <style type="text/css">
      body {
        padding-top: 40px;
        padding-bottom: 40px;
        background-color: #f5f5f5;
      }

      .form-signin {
        max-width: 300px;
        padding: 19px 29px 29px;
        margin: 0 auto 20px;
        background-color: #fff;
        border: 1px solid #e5e5e5;
        -webkit-border-radius: 5px;
           -moz-border-radius: 5px;
                border-radius: 5px;
        -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
           -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
                box-shadow: 0 1px 2px rgba(0,0,0,.05);
      }
      .form-signin .form-signin-heading,
      .form-signin input[type="text"],
      .form-signin input[type="password"] {
        font-size: 16px;
        height: auto;
        margin-bottom: 15px;
      }

    </style>

  </head>

  
  
  <body>

    <div class="container">

      <form class="form-signin" action="login.php" method="POST">
        <h2 class="form-signin-heading">Please sign in</h2>
          	
        <?php if($error) :?>	
  		<div class="alert alert-error">  
  			<a class="close" data-dismiss="alert">×</a>  
  			<strong>Error!</strong> Invalid email or password
		</div>
		<?php endif; ?>
		
        <div class="input-prepend control-group <?php if($error) echo 'error';?>">
			<div>        
        		<span class="add-on"><i class="icon-envelope"></i></span>
  				<input type="text" name="TS_email" class="input-block-level" placeholder="Email address" autocomplete="off">
  			</div>
  			<div>
  				<span class="add-on"><i class="icon-lock"></i></span>
  				<input type="password" name="TS_password" class="input-block-level" placeholder="Password" autocomplete="off">
  			</div>
  		</div>
        <button class="btn btn-large btn-primary" type="submit">Sign in</button>
      </form>

    </div> <!-- /container -->

  </body>
</html>
